package com.pajk.user.service.common.metaq;

import org.apache.commons.lang3.StringUtils;

/**
 * User: haihua.chenhh
 * Date: 14-3-20
 * Time: 上午11:39
 */
public enum TopicEnum {
    USER_ADD_CREDIT("USER", "ADD_CREDIT", "积分操作事件"),
    USER_SYNC_CREDIT_TO_WLT("USER", "SYNC_CREDIT", "积分操作事件"),
    USER_CONSUME_CREDIT("USER", "CONSUME_CREDIT", "积分操作事件"),
    USER_SMS_UPSTREAM("USER","SMS_UPSTREAM","短信上行事件");
    /**
     * 主题
     */
    private String topic;

    /**
     * 标签
     */
    private String tags;

    /**
     * 描述
     */
    private String desc;

    public String getTopic() {
        return topic;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }


    public String getDesc() {
        return desc;
    }


    public void setDesc(String desc) {
        this.desc = desc;
    }


    private TopicEnum(String topic, String tags, String desc) {
        this.topic = topic;
        this.tags = tags;
        this.desc = desc;
    }

    public String[] getTopicAndTag() {
        return new String[]{topic, tags, desc};
    }

    /**
     * code和枚举转换.
     *
     * @return topicEnum
     */
    public static TopicEnum findTopicEnum(String topic, String tags) {
        for (TopicEnum topicEnum : TopicEnum.class.getEnumConstants()) {
            if (StringUtils.equals(topicEnum.getTopic(), topic)
                    && StringUtils.equals(topicEnum.getTags(), tags)) {
                return topicEnum;
            }
        }
        return null;
    }

    public String getTopicStr() {
        return topic + "," + tags;
    }

    public static TopicEnum getTopicEnumFromStr(String desc) {
        String[] tags = desc.split(",");
        return findTopicEnum(tags[0], tags[1]);
    }
}
